<template>
  <div class="app-container">
    <h2>支付首页</h2>
    <el-form :model="payForm" label-width="100px">
      <el-form-item label="订单编号">
        <el-input v-model="payForm.orderNumber" placeholder="请输入订单编号" />
      </el-form-item>
      <el-form-item label="支付金额">
        <el-input-number v-model="payForm.amount" :min="0.01" :step="0.01" placeholder="请输入支付金额" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="createAlipayOrder">立即支付</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createAlipayOrder } from '@/api/pay'

export default {
  name: 'PayIndex',
  data() {
    return {
      payForm: {
        orderNumber: '',
        amount: 0.01
      }
    }
  },
  methods: {
    async createAlipayOrder() {
      if (!this.payForm.orderNumber || this.payForm.amount <= 0) {
        this.$message.error('请正确填写支付信息！');
        return;
      }
      const response = await createAlipayOrder(this.payForm)
      document.write(response) // 渲染支付宝支付页面
    }
  }
}
</script>
